package com.itrip.controller;

import com.itrip.document.Hotel;
import com.itrip.dto.HotelRoomDTO;
import com.itrip.dto.ResponseDTO;
import com.itrip.service.HotelService;
import io.swagger.annotations.*;
import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@Api(tags = "酒店相关接口")
@ApiResponses({
        @ApiResponse(code = 200,message = "请求正常",response = ResponseDTO.class)
})
@RestController
public class HotelController {
    @Resource
    private HotelService hotelService;

    @GetMapping("/getHotelByQuery")
    @ApiOperation("查询酒店列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword",value = "关键词"),
            @ApiImplicitParam(name = "pageNow",value = "页码",required = true),
            @ApiImplicitParam(name = "pageSize",value = "显示行数",required = true),
    })
    public ResponseDTO getHotelByQuery(String keyword,@RequestParam Integer pageNow,@RequestParam Integer pageSize) throws IOException, SolrServerException {
        List<Hotel> hotelList = hotelService.getHotelByQuery(keyword,pageNow,pageSize);
        return new ResponseDTO(100,"查询酒店列表成功",hotelList);
    }

    @GetMapping("/getHotelCount")
    @ApiOperation("查询酒店数量")
    @ApiImplicitParam(name = "keyword",value = "关键词")
    public ResponseDTO getHotelCount(@RequestParam String keyword) throws IOException, SolrServerException {
        Long count = hotelService.getHotelCount(keyword);
        return new ResponseDTO(100,"查询酒店数量成功",count);
    }

    @GetMapping("/getHotelRoomList")
    @ApiOperation("查询酒店房间列表")
    @ApiImplicitParam(name = "id",value = "酒店ID",required = true)
    public ResponseDTO getHotelRoomList(@RequestParam Integer id) throws IOException, SolrServerException {
        HotelRoomDTO hotelRoomDTO = hotelService.getHotelRoomList(id);
        return new ResponseDTO(100,"查询酒店房间列表成功",hotelRoomDTO);
    }
}
